package com.chaosj.tools

import com.google.common.base.Strings

/**
 * @Description:
 * @author caoyangjie
 * @date 2020年03月2020/3/2日 11:04
 * @Copyright: © 赢时胜
 */
class StockMarketTools {
    static void main(args){
        def stocks = new ArrayList(64)
        stocks.add(new Stock("全新好","000007",30000,9.30,11.5))
        stocks.add(new Stock("京东方A","000725",30000,5.20,6.6))
        stocks.add(new Stock("中国铁建","601186",15000,10.09,12))
        stocks.add(new Stock("中国建筑","601668",15000,5.79,6.2))


        def findStockByName = ""
        stocks.stream().filter({s->
            Stock stock = s
            if( findStockByName == "" || findStockByName == stock.name ){
                return true
            }
            return false
        }).forEach({ s->
            Stock stock = s
            println(new ShowTemplate(stock.currentPrice,stock.targetPrice,stock.name,stock.code,stock.wannaBuyMoney).printString())
            println("####################################################################################################")
        })
    }

    static class Stock{
        // 股票名称
        def name
        def code
        def wannaBuyMoney
        def currentPrice
        def targetPrice

        Stock(name, code, wannaBuyMoney, currentPrice, targetPrice) {
            this.name = name
            this.code = code
            this.wannaBuyMoney = wannaBuyMoney
            this.currentPrice = currentPrice
            this.targetPrice = targetPrice
        }
    }

    static class ShowTemplate{
        def buyTitle = "| 买入档次            | 第一次追加价            | 第二次追加价          | 第三次追加                |\n"
        def slice = "| ------------------- | ----------------------- | --------------------- | ------------------------- |\n"
        def sellTitle = "| 止损档次            | 第一次追加回撤          | 第二次追加回撤        | 第三次追加回撤            |\n"
        def buyMoneyTemplate = "| %10.2f          | %10.2f              | %10.2f            | %10.2f                |\n"
        def buyCountTemplate = "| %10.0f          | %10.0f              | %10.0f            | %10.0f                |\n"
        def sellMoneyTemplate = "| %10.2f          | %10.2f              | %10.2f            | %10.2f                |\n"
        def sellCountTemplate = "| %10.0f          | %10.0f              | %10.0f            | %10.0f                |\n"
        def headTemplate = "%s(%s): 目标价格[%s]\n"

        ShowTemplate(buyMoney,targetMoney,name,code,totalMoney) {
            headTemplate = Strings.lenientFormat(headTemplate,name,code,targetMoney)
            buyMoneyTemplate = String.format(buyMoneyTemplate,buyMoney,(buyMoney*1.05),(buyMoney*1.05*1.05),(buyMoney*1.05*1.05*1.05))
            buyCountTemplate = String.format(buyCountTemplate,(totalMoney/buyMoney*0.4)/100,(totalMoney/buyMoney*0.3)/100,(totalMoney/buyMoney*0.2)/100,(totalMoney/buyMoney*0.1)/100)
            sellMoneyTemplate = String.format(sellMoneyTemplate,(buyMoney*0.95),(buyMoney*1.025),(buyMoney*1.05*1.025),(buyMoney*1.05*1.05*1.025))
            sellCountTemplate = String.format(sellCountTemplate,totalMoney/buyMoney*0.4/100,totalMoney/buyMoney*0.4/100,totalMoney/buyMoney*0.5/100,totalMoney/buyMoney*0.3/100)
        }

        String printString() {
            return headTemplate +
            "\n" +
            buyTitle +
            slice +
            buyMoneyTemplate +
            buyCountTemplate +
            "\n" +
            sellTitle +
            slice +
            sellMoneyTemplate +
            sellCountTemplate
        }
    }
}
